package com.tcpudp.service;

import com.tcpudp.model.User;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

@Service
public class UserService {
    private final Map<String, User> users = new HashMap<>();
    
    @PostConstruct
    public void init() {
        // 初始化默认管理员用户
        User admin = new User();
        admin.setUsername("admin");
        admin.setPassword("admin123"); // 实际应用中应该使用加密密码
        admin.setRole("ADMIN");
        users.put(admin.getUsername(), admin);
    }
    
    public User findByUsername(String username) {
        return users.get(username);
    }
    
    public boolean validateUser(String username, String password) {
        User user = findByUsername(username);
        return user != null && user.getPassword().equals(password);
    }
}